package com.example.module.iot.aws.util;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import software.amazon.awssdk.crt.mqtt.MqttClientConnection;
import software.amazon.awssdk.crt.mqtt.MqttMessage;
import software.amazon.awssdk.crt.mqtt.QualityOfService;

@Slf4j
@RequiredArgsConstructor
public class AwsMqttUtils {

    private final MqttClientConnection connection;

    @SneakyThrows
    public Integer publish(String topic, String message) {
        MqttMessage mqttMessage = new MqttMessage(topic, message.getBytes(), QualityOfService.AT_LEAST_ONCE, false);
        return connection.publish(mqttMessage).get();
    }
}
